using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Plugin;
using MicroMsg.Plugin.LBS;
using MicroMsg.Resource.@string;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class LbsPluginSetCtrl : PluginSettingBaseCtrl
	{
		private const string TAG = "LbsPluginSetCtrl";
		private EventWatcher mWatcherLbsRemove;
		private object mObject = new object();
		private MMMessageBox mMsgBoxClearFailed;
		internal Grid LayoutRoot;
		internal Button btnGotoLbs;
		internal Button btnClearLocation;
		private bool _contentLoaded;
		public static LbsPluginSetCtrl GetInstance()
		{
			return new LbsPluginSetCtrl();
		}
		~LbsPluginSetCtrl()
		{
			this.unInitEventWatcher();
		}
		public LbsPluginSetCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.LbsPluginSetCtrl_Loaded));
		}
		private void LbsPluginSetCtrl_Loaded(object sender, RoutedEventArgs e)
		{
		}
		public override void Exit()
		{
			base.Exit();
		}
		private void btnGotoLbs_Click(object sender, RoutedEventArgs e)
		{
			PluginBase pluginBase = ExtentCenter.findPluginByID(32773L);
			if (pluginBase != null)
			{
				pluginBase.execute(4, null);
			}
		}
		private void btnClearLocation_Click(object sender, RoutedEventArgs e)
		{
			this.clearPosition();
		}
		private void clearPosition()
		{
			LBS.getInstance().sceneLbsService.doCleanPosition();
			this.initEventWatcher();
		}
		private void initEventWatcher()
		{
			if (this.mWatcherLbsRemove == null)
			{
				this.mWatcherLbsRemove = new EventWatcher(this.mObject, null, new EventHandlerDelegate(this.onEventHandlerLbsRemove));
			}
			EventCenter.registerEventWatcher(EventConst.ON_LBS_REMOVE_SUCCESS, this.mWatcherLbsRemove);
			EventCenter.registerEventWatcher(EventConst.ON_LBS_REMOVE_ERROR, this.mWatcherLbsRemove);
		}
		private void unInitEventWatcher()
		{
			if (this.mWatcherLbsRemove != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_LBS_REMOVE_SUCCESS, this.mWatcherLbsRemove);
				EventCenter.removeEventWatcher(EventConst.ON_LBS_REMOVE_ERROR, this.mWatcherLbsRemove);
				this.mWatcherLbsRemove = null;
			}
		}
		private void onEventHandlerLbsRemove(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.unInitEventWatcher();
			if (EventConst.ON_LBS_REMOVE_SUCCESS == evtArgs.mEventID)
			{
				MessageBoxManager.ShowToast(strings.Lbs_PeoList_MsgClearSucc, 2500, null, false);
				return;
			}
			if (EventConst.ON_LBS_REMOVE_ERROR == evtArgs.mEventID)
			{
				if (this.mMsgBoxClearFailed == null)
				{
					this.mMsgBoxClearFailed = MMMessageBox.Show(strings.Lbs_PeoList_MsgClearFaild, "", true, strings.COM_Retry, strings.COM_Cancel);
					this.mMsgBoxClearFailed.ReturnEvent = new DlgReturnEvent(this.MsgBoxClearPositionHandler);
				}
				Log.smethod_5("LbsPluginSetCtrl", "ON_LBS_REMOVE_ERROR");
			}
		}
		public void MsgBoxClearPositionHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			this.mMsgBoxClearFailed = null;
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.clearPosition();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Lbs/UI/LbsPluginSetCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.btnGotoLbs = (Button)base.FindName("btnGotoLbs");
			this.btnClearLocation = (Button)base.FindName("btnClearLocation");
		}
	}
}
